//
//  Logger.swift
//  xz-app
//
//  Created by chen on 2025/5/7.
//
import SwiftyBeaver

class Logger {
    
    static let shared = Logger()
    private let log = SwiftyBeaver.self
    
    private init() {
        // 控制台输出
        let console = ConsoleDestination()
        console.format = "$DYYYY-MM-dd HH:mm:ss.SSS$d [$L] $N.$F:$l - $M"
        
        // 设置日志颜色
        console.levelColor.verbose = "⚪️ "  // 白色
        console.levelColor.debug = "🔵 "    // 蓝色
        console.levelColor.info = "🟢 "     // 绿色
        console.levelColor.warning = "🟡 "  // 黄色
        console.levelColor.error = "🔴 "    // 红色
        
        log.addDestination(console)
        
        // 文件输出
//        let file = FileDestination()
//        file.format = "$DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M"
        
        //log.addDestination(file)
    }
    
    func debug(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
        log.debug(message, file: file, function: function, line: line)
    }
    
    func info(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
        log.info(message, file: file, function: function, line: line)
    }
    
    func warning(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
        log.warning(message, file: file, function: function, line: line)
    }
    
    func error(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
        log.error(message, file: file, function: function, line: line)
    }
}
